import time
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
driver.maximize_window()

time.sleep(2)
# 定位输入框  输入内容
driver.find_element(By.ID, "kw").send_keys("python")
# 点击
driver.find_element(By.ID, "su").click()
# # 第一种写法
# # 滚动到页面底部
# time.sleep(2)
# js1 = "window.scrollTo(0, document.body.scrollHeight)"
# driver.execute_script(js1)
#
# # 滚动到页面顶部
# time.sleep(2)
# js2 = "window.scrollTo(0, 0)"
# driver.execute_script(js2)

# 第二种写法 instant 瞬间滑动 smooth 平稳滑动
time.sleep(2)
js3 = "window.scrollTo({left:0,top:document.body.scrollHeight,behavior:'smooth'})"
driver.execute_script(js3)

# 回到顶层
time.sleep(2)
js4 = "window.scrollTo(0, 0)"
driver.execute_script(js4)
# 聚焦
ele = driver.find_element(By.PARTIAL_LINK_TEXT, "菜鸟教程")
driver.execute_script("arguments[0].scrollIntoView();", ele)
time.sleep(2)

time.sleep(2)
driver.quit()


